package com.tidc.seaservermodel.entity;

import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.sql.Timestamp;
import java.util.Date;
import java.io.Serializable;

/**
 * (Commitment)实体类
 *
 * @author makejava
 * @since 2020-10-06 16:35:31
 */
@Data
@Accessors(chain = true) //这个注解可以使这个类的set方法返回当前对象
@NoArgsConstructor
public class Commitment implements Serializable {
    private static final long serialVersionUID = -91243780283936003L;
    
    private Integer id;
    
    private Integer askUserId;
    private String askUsername;
    private Integer acceptorUserId;
    
    private Integer shopId;
    
    private String shopName;
    
    private String shopIntroduce;
    
    private Integer amount;
    /**
    * 0 未完成 1已完成 2已过期
    */
    private Integer statusType;

    private Timestamp createTime;
    
    private Timestamp finishTime;

    private Timestamp expirationTime;

    private Integer timeout;

    public static Commitment addCommitment(UserPackage userPackage, int amount,int acceptorUserId){
        Commitment commitment = new Commitment();
        commitment.setAmount(amount);
        commitment.setShopId(userPackage.getShopId());
        commitment.setShopName(userPackage.getShopName());
        commitment.setShopIntroduce(userPackage.getShopIntroduce());
        commitment.setStatusType(0);
        commitment.setAcceptorUserId(acceptorUserId);
        commitment.setAskUserId(userPackage.getUserId());
        commitment.setTimeout(userPackage.getTimeout());
        long timeMillis = System.currentTimeMillis() + 1000*60*60*userPackage.getTimeout();
        commitment.setExpirationTime(new Timestamp(timeMillis));
        return commitment;
    }



}